From 733a32916031526d970f9acc5aae853a4ce99db3 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Mon, 17 Jun 2013 12:03:02 +0200 Subject: [PATCH 01/10] Upgraded to work with QGIS 2.0. New SIP bindings --- src/geosearch_dk/autosuggest.py | 40 +++++++++++++--------------- src/geosearch_dk/metadata.txt | 6 ++--- src/geosearch_dk/searchbox.py | 37 ++++++++++++------------- src/geosearch_dk/septimageosearch.py | 8 +++--- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/geosearch_dk/autosuggest.py b/src/geosearch_dk/autosuggest.py index 8073859..4d12322 100644 --- a/src/geosearch_dk/autosuggest.py +++ b/src/geosearch_dk/autosuggest.py @@ -59,8 +59,9 @@ def __init__(self, geturl_func, parseresult_func, parent = None): self.popup.installEventFilter(self) self.popup.setMouseTracking(True) - self.connect(self.popup, SIGNAL("itemClicked(QTreeWidgetItem*, int)"), - self.doneCompletion) + #self.connect(self.popup, SIGNAL("itemClicked(QTreeWidgetItem*, int)"), + # self.doneCompletion) + self.popup.itemClicked.connect( self.doneCompletion ) self.popup.setWindowFlags(Qt.Popup) self.popup.setFocusPolicy(Qt.NoFocus) @@ -69,11 +70,16 @@ def __init__(self, geturl_func, parseresult_func, parent = None): self.timer = QTimer(self) self.timer.setSingleShot(True) self.timer.setInterval(500) - self.connect(self.timer, SIGNAL("timeout()"), self.autoSuggest) - self.connect(self.editor, SIGNAL("textEdited(QString)"), self.timer, SLOT("start()")) + #self.connect(self.timer, SIGNAL("timeout()"), self.autoSuggest) + self.timer.timeout.connect( self.autoSuggest ) + + #self.connect(self.editor, SIGNAL("textEdited(QString)"), self.timer, SLOT("start()")) + #self.editor.textEdited.connect( self.timer.start ) + self.editor.textEdited.connect( self.timer.start ) - self.connect(self.networkManager, SIGNAL("finished(QNetworkReply*)"), - self.handleNetworkData) + #self.connect(self.networkManager, SIGNAL("finished(QNetworkReply*)"), + # self.handleNetworkData) + self.networkManager.finished.connect( self.handleNetworkData ) def eventFilter(self, obj, ev): if obj != self.popup: @@ -125,7 +131,7 @@ def showCompletion(self, rows): #item.setText(1, hit['type']) item.setTextAlignment(1, Qt.AlignRight) item.setTextColor(1, color) - item.setData(2, Qt.UserRole, QVariant((row[1],))) # Try immutable py obj #http://stackoverflow.com/questions/9257422/how-to-get-the-original-python-data-from-qvariant + item.setData(2, Qt.UserRole, (row[1],)) # Try immutable py obj #http://stackoverflow.com/questions/9257422/how-to-get-the-original-python-data-from-qvariant self.popup.setCurrentItem(self.popup.topLevelItem(0)) self.popup.resizeColumnToContents(0) @@ -147,11 +153,8 @@ def doneCompletion(self): item = self.popup.currentItem() if item: self.editor.setText(item.text(0) ) - o = item.data(2, Qt.UserRole) #.toPyObject() - #print o - pyobj = o.toPyObject() - #print pyobj - self.selectedObject = pyobj[0] + obj = item.data(2, Qt.UserRole) #.toPyObject() + self.selectedObject = obj[0] e = QKeyEvent(QEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier) QApplication.postEvent(self.editor, e) e = QKeyEvent(QEvent.KeyRelease, Qt.Key_Enter, Qt.NoModifier) @@ -162,15 +165,14 @@ def preventSuggest(self): def autoSuggest(self): term = self.editor.text() - if not term.isEmpty(): + if term: qurl = self.geturl( term ) - #print "URL: ", self.QstringToStr( qurl.toString() ) # TODO: Cancel existing requests: http://qt-project.org/forums/viewthread/18073 self.networkManager.get(QNetworkRequest( qurl )) #QUrl(url))) def handleNetworkData(self, networkReply): - #url = networkReply.url() - # print "received url:", self.QstringToStr( url.toString() ) + url = networkReply.url() + #print "received url:", url.toString() if not networkReply.error(): response = networkReply.readAll() #print "Response: ", response @@ -182,8 +184,4 @@ def handleNetworkData(self, networkReply): def unload( self ): # Avoid processing events after QGIS shutdown has begun self.popup.removeEventFilter(self) - self.isUnloaded = True - - def QstringToStr(self, qstring): - return unicode(qstring.toUtf8(),'utf-8').encode('latin_1', 'replace') - + self.isUnloaded = True \ No newline at end of file diff --git a/src/geosearch_dk/metadata.txt b/src/geosearch_dk/metadata.txt index a310bb1..aa1cba1 100644 --- a/src/geosearch_dk/metadata.txt +++ b/src/geosearch_dk/metadata.txt @@ -10,10 +10,10 @@ [general] name=Geosearch DK -qgisMinimumVersion=1.8 -qgisMaximumVersion=1.99 +qgisMinimumVersion=2.0 +qgisMaximumVersion=2.99 description=Zoom to named places in Denmark. Uses Kortforsyningen. Developed by Septima. -version=0.1.21 +version=0.1.22 author=Asger Skovbo Petersen, Septima email=asger@septima.dk diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index 7caf72f..c0cc537 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -17,7 +17,7 @@ * * ***************************************************************************/ """ -BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&search=%1&resources={resources}&limit={limit}&login={login}&password={password}&callback={callback}" +BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&limit={limit}&login={login}&password={password}&callback={callback}&search=" RESOURCES = "Adresser,Stednavne,Postdistrikter,Matrikelnumre,Kommuner,Opstillingskredse,Politikredse,Regioner,Retskredse" from PyQt4.QtGui import * @@ -50,13 +50,13 @@ def __init__(self, qgisIface): self.completion = AutoSuggest(geturl_func = self.geturl, parseresult_func = self.parseresponse, parent = self.ui.searchEdit) self.setupCrsTransform() - self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.doSearch) - #self.connect(self.ui.searchButton, SIGNAL("clicked()"), self.doSearch) - #self.connect(self.ui.clearButton, SIGNAL("clicked()"), self.clear) + #self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.doSearch) + self.ui.searchEdit.returnPressed.connect( self.doSearch ) # Listen to crs changes - self.connect( self.qgisIface.mapCanvas().mapRenderer(), SIGNAL("destinationSrsChanged()"), self.setupCrsTransform ) - self.connect( self.qgisIface.mapCanvas().mapRenderer(), SIGNAL("hasCrsTransformEnabled(bool)"), self.setupCrsTransform ) - #self.qgisIface.mapCanvas().mapRenderer().setProjectionsEnabled(True) + #self.connect( self.qgisIface.mapCanvas().mapRenderer(), SIGNAL("destinationSrsChanged()"), self.setupCrsTransform ) + self.qgisIface.mapCanvas().mapRenderer().destinationSrsChanged.connect( self.setupCrsTransform ) + #self.connect( self.qgisIface.mapCanvas().mapRenderer(), SIGNAL("hasCrsTransformEnabled(bool)"), self.setupCrsTransform ) + self.qgisIface.mapCanvas().mapRenderer().hasCrsTransformEnabled.connect( self.setupCrsTransform ) self.adjustSize() self.resize(50, self.height()) @@ -66,11 +66,11 @@ def readconfig(self): s = QSettings() k = __package__ self.config = { - 'username': str(s.value( k + "/username", "").toString()), - 'password': str(s.value( k + "/password", "").toString()), - 'resources': str(s.value( k + "/resources", RESOURCES).toString()) , - 'maxresults': s.value( k + "/maxresults", 25).toInt()[0], - 'callback': str(s.value( k + "/callback", "callback").toString()), + 'username': str(s.value( k + "/username", "", type=str)), + 'password': str(s.value( k + "/password", "", type=str)), + 'resources': str(s.value( k + "/resources", RESOURCES, type=str)) , + 'maxresults': s.value( k + "/maxresults", 25, type=int), + 'callback': str(s.value( k + "/callback", "callback", type=str)), } def updateconfig( self ): @@ -83,13 +83,14 @@ def updateconfig( self ): s.setValue(k + "/callback", self.config['callback']) def geturl(self, searchterm): - url = QString( BASEURL.format( + url = BASEURL.format( resources = self.config['resources'], limit = self.config['maxresults'], login = self.config['username'], password = self.config['password'], - callback = self.config['callback'])) - return QUrl( url.arg( searchterm ) ) + callback = self.config['callback']) + url += searchterm + return QUrl( url ) def parseresponse(self, response): @@ -217,14 +218,14 @@ def show_settings_dialog(self): self.updateconfig() def show_about_dialog(self): - infoString = QString(QCoreApplication.translate('Geosearch DK', + infoString = QCoreApplication.translate('Geosearch DK', u"Geosearch DK lader brugeren zoome til navngivne steder i Danmark.
" - u"Pluginet benytter tjenesten 'geosearch' fra kortforsyningen.dk/" + u"Pluginet benytter tjenesten 'geosearch' fra kortforsyningen.dk" u" og kræver derfor et gyldigt login til denne tjeneste.
" u"Pluginets webside: github.com/Septima/qgis-geosearch
" u"Udviklet af: Septima
" u"Mail: kontakt@septima.dk
" - u"Web: www.septima.dk\n")) + u"Web: www.septima.dk\n") QMessageBox.information(self.qgisIface.mainWindow(), "Om Geosearch DK",infoString) def unload( self ): diff --git a/src/geosearch_dk/septimageosearch.py b/src/geosearch_dk/septimageosearch.py index 82a1d8c..803cf40 100644 --- a/src/geosearch_dk/septimageosearch.py +++ b/src/geosearch_dk/septimageosearch.py @@ -45,7 +45,7 @@ def __init__(self, iface): # initialize locale localePath = "" - locale = self.config.value("locale/userLocale").toString()[0:2] + locale = self.config.value("locale/userLocale")[0:2] if QFileInfo(self.plugin_dir).exists(): localePath = self.plugin_dir + "/i18n/" + __package__ + locale + ".qm" @@ -71,8 +71,10 @@ def initGui(self): self.configAction=QAction(QIcon(), QCoreApplication.translate('Geosearch DK', "&Indstillinger"), self.iface.mainWindow()) self.aboutAction=QAction(QIcon(), QCoreApplication.translate('Geosearch DK', "&Om pluginet"), self.iface.mainWindow()) - QObject.connect(self.configAction, SIGNAL("activated()"), self.searchwidget.show_settings_dialog) - QObject.connect(self.aboutAction, SIGNAL("activated()"), self.searchwidget.show_about_dialog) + #QObject.connect(self.configAction, SIGNAL("activated()"), self.searchwidget.show_settings_dialog) + self.configAction.activated.connect( self.searchwidget.show_settings_dialog ) + #QObject.connect(self.aboutAction, SIGNAL("activated()"), self.searchwidget.show_about_dialog) + self.aboutAction.activated.connect( self.searchwidget.show_about_dialog ) self.iface.addPluginToMenu("Geosearch DK", self.configAction) self.iface.addPluginToMenu("Geosearch DK", self.aboutAction) From 44f1c22e69196982080b8026bde870e4faf3dcc5 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 09:54:36 +0100 Subject: [PATCH 02/10] Settings dialog --- src/geosearch_dk/ui_settings.ui | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index 957dcfd..4cf50ab 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -25,6 +25,9 @@ + + 0 + Kortforsyningen @@ -62,6 +65,40 @@ + + + Kommunefilter + + + + + 10 + 10 + 291 + 71 + + + + + + + Kommunekoder + + + + + + + + + + Eksempel: 101,111,122 + + + + + + From d4171b8464e1752906ff3a70f0e2ac1cc53d1c60 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 09:56:22 +0100 Subject: [PATCH 03/10] basic implementation --- src/geosearch_dk/searchbox.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index c0cc537..e28c181 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -17,7 +17,7 @@ * * ***************************************************************************/ """ -BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&limit={limit}&login={login}&password={password}&callback={callback}&search=" +BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&area={area}&limit={limit}&login={login}&password={password}&callback={callback}&search=" RESOURCES = "Adresser,Stednavne,Postdistrikter,Matrikelnumre,Kommuner,Opstillingskredse,Politikredse,Regioner,Retskredse" from PyQt4.QtGui import * @@ -71,24 +71,28 @@ def readconfig(self): 'resources': str(s.value( k + "/resources", RESOURCES, type=str)) , 'maxresults': s.value( k + "/maxresults", 25, type=int), 'callback': str(s.value( k + "/callback", "callback", type=str)), + 'muncodes': s.value(k + "/muncodes", []) } def updateconfig( self ): s = QSettings() k = __package__ - s.setValue(k + "/username", self.config['username']) - s.setValue(k + "/password", self.config['password']) - s.setValue(k + "/resources", self.config['resources']) - s.setValue(k + "/maxresults", self.config['maxresults']) - s.setValue(k + "/callback", self.config['callback']) + s.setValue(k + "/username", self.config['username']) + s.setValue(k + "/password", self.config['password']) + s.setValue(k + "/resources", self.config['resources']) + s.setValue(k + "/maxresults", self.config['maxresults']) + s.setValue(k + "/callback", self.config['callback']) + s.setValue(k + "/muncodes", self.config['muncodes']) def geturl(self, searchterm): url = BASEURL.format( resources = self.config['resources'], - limit = self.config['maxresults'], - login = self.config['username'], - password = self.config['password'], - callback = self.config['callback']) + limit = self.config['maxresults'], + login = self.config['username'], + password = self.config['password'], + callback = self.config['callback'], + area = ','.join(['muncode0'+str(k) for k in self.config['muncodes']]) + ) url += searchterm return QUrl( url ) @@ -215,6 +219,7 @@ def show_settings_dialog(self): # save settings self.config['username'] = str(dlg.loginLineEdit.text()) self.config['password'] = str(dlg.passwordLineEdit.text()) + self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',')] self.updateconfig() def show_about_dialog(self): From 74c1fb86f44c6df317d8fbdfb1723efb8928b25c Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 10:00:06 +0100 Subject: [PATCH 04/10] Correct example string --- src/geosearch_dk/ui_settings.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index 4cf50ab..faf8ff7 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -92,7 +92,7 @@ - Eksempel: 101,111,122 + Eksempel: 101,147,157 From dfc66a4990f423b3dfda659378f5898c3a4ec6e1 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 12 May 2015 13:03:53 +0200 Subject: [PATCH 05/10] Small fixes --- src/geosearch_dk/searchbox.py | 4 +++- src/geosearch_dk/settingsdialog.py | 6 ++++++ src/geosearch_dk/ui_settings.ui | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index e28c181..57681ce 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -85,6 +85,7 @@ def updateconfig( self ): s.setValue(k + "/muncodes", self.config['muncodes']) def geturl(self, searchterm): + # TODO: prepare what can be prepared url = BASEURL.format( resources = self.config['resources'], limit = self.config['maxresults'], @@ -210,6 +211,7 @@ def show_settings_dialog(self): dlg = settingsdialog.SettingsDialog() dlg.loginLineEdit.setText(self.config['username']) dlg.passwordLineEdit.setText(self.config['password']) + dlg.kommunekoderLineEdit.setText(','.join(map(str, self.config['muncodes']))) # show the dialog dlg.show() result = dlg.exec_() @@ -219,7 +221,7 @@ def show_settings_dialog(self): # save settings self.config['username'] = str(dlg.loginLineEdit.text()) self.config['password'] = str(dlg.passwordLineEdit.text()) - self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',')] + self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',') if not k.strip() == '' ] self.updateconfig() def show_about_dialog(self): diff --git a/src/geosearch_dk/settingsdialog.py b/src/geosearch_dk/settingsdialog.py index c836f39..ff507dd 100644 --- a/src/geosearch_dk/settingsdialog.py +++ b/src/geosearch_dk/settingsdialog.py @@ -21,7 +21,13 @@ from PyQt4.QtGui import * from ui_settings import Ui_Dialog +MUNCODE_REGEX = '[0-9,]*' + class SettingsDialog (QDialog, Ui_Dialog): def __init__(self): QDialog.__init__(self) self.setupUi(self) + + regex = QRegExp('', Qt.CaseInsensitive) + self.muncodeValidator = QRegExpValidator( MUNCODE_REGEX ) + self.kommunekoderLineEdit.setValidator( self.muncodeValidator, self.kommunekoderLineEdit ) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index faf8ff7..6998df4 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -26,7 +26,7 @@ - 0 + 1 From f0b1ce20f8c64829d9474ce05293cc3e45eb7956 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 09:54:36 +0100 Subject: [PATCH 06/10] Settings dialog --- src/geosearch_dk/ui_settings.ui | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index 957dcfd..4cf50ab 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -25,6 +25,9 @@ + + 0 + Kortforsyningen @@ -62,6 +65,40 @@ + + + Kommunefilter + + + + + 10 + 10 + 291 + 71 + + + + + + + Kommunekoder + + + + + + + + + + Eksempel: 101,111,122 + + + + + + From a854829d5666b76d9d5251f9bfd95b186fa7eec8 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 09:56:22 +0100 Subject: [PATCH 07/10] basic implementation --- src/geosearch_dk/searchbox.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index e4927e9..881b114 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -17,7 +17,7 @@ * * ***************************************************************************/ """ -BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&limit={limit}&login={login}&password={password}&callback={callback}&search=" +BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&area={area}&limit={limit}&login={login}&password={password}&callback={callback}&search=" RESOURCES = "Adresser,Stednavne,Postdistrikter,Matrikelnumre,Kommuner,Opstillingskredse,Politikredse,Regioner,Retskredse" from PyQt4.QtGui import * @@ -77,16 +77,18 @@ def readconfig(self): 'resources': str(s.value(k + "/resources", RESOURCES, type=str)), 'maxresults': s.value(k + "/maxresults", 25, type=int), 'callback': str(s.value(k + "/callback", "callback", type=str)), + 'muncodes': s.value(k + "/muncodes", []) } def updateconfig(self): s = QSettings() k = __package__ - s.setValue(k + "/username", self.config['username']) - s.setValue(k + "/password", self.config['password']) - s.setValue(k + "/resources", self.config['resources']) - s.setValue(k + "/maxresults", self.config['maxresults']) - s.setValue(k + "/callback", self.config['callback']) + s.setValue(k + "/username", self.config['username']) + s.setValue(k + "/password", self.config['password']) + s.setValue(k + "/resources", self.config['resources']) + s.setValue(k + "/maxresults", self.config['maxresults']) + s.setValue(k + "/callback", self.config['callback']) + s.setValue(k + "/muncodes", self.config['muncodes']) def geturl(self, searchterm): url = BASEURL.format( @@ -94,7 +96,8 @@ def geturl(self, searchterm): limit=self.config['maxresults'], login=self.config['username'], password=self.config['password'], - callback=self.config['callback'] + callback=self.config['callback'], + area=','.join(['muncode0'+str(k) for k in self.config['muncodes']]) ) url += searchterm return QUrl(url) @@ -226,6 +229,7 @@ def show_settings_dialog(self): # save settings self.config['username'] = str(dlg.loginLineEdit.text()) self.config['password'] = str(dlg.passwordLineEdit.text()) + self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',')] self.updateconfig() def show_about_dialog(self): From 87b46cd0bdc4eed144e3a43c61f3d9e1680026ec Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 5 Nov 2013 10:00:06 +0100 Subject: [PATCH 08/10] Correct example string --- src/geosearch_dk/ui_settings.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index 4cf50ab..faf8ff7 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -92,7 +92,7 @@ - Eksempel: 101,111,122 + Eksempel: 101,147,157 From a801f120cbfe7c9a32534d4d8d5614718ce3cec0 Mon Sep 17 00:00:00 2001 From: AsgerPetersen Date: Tue, 12 May 2015 13:03:53 +0200 Subject: [PATCH 09/10] Small fixes --- src/geosearch_dk/searchbox.py | 4 +++- src/geosearch_dk/settingsdialog.py | 11 ++++++++++- src/geosearch_dk/ui_settings.ui | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index 881b114..d5acd6f 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -91,6 +91,7 @@ def updateconfig(self): s.setValue(k + "/muncodes", self.config['muncodes']) def geturl(self, searchterm): + # TODO: prepare what can be prepared url = BASEURL.format( resources=self.config['resources'], limit=self.config['maxresults'], @@ -220,6 +221,7 @@ def show_settings_dialog(self): dlg = settingsdialog.SettingsDialog() dlg.loginLineEdit.setText(self.config['username']) dlg.passwordLineEdit.setText(self.config['password']) + dlg.kommunekoderLineEdit.setText(','.join(map(str, self.config['muncodes']))) # show the dialog dlg.show() result = dlg.exec_() @@ -229,7 +231,7 @@ def show_settings_dialog(self): # save settings self.config['username'] = str(dlg.loginLineEdit.text()) self.config['password'] = str(dlg.passwordLineEdit.text()) - self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',')] + self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',') if not k.strip() == '' ] self.updateconfig() def show_about_dialog(self): diff --git a/src/geosearch_dk/settingsdialog.py b/src/geosearch_dk/settingsdialog.py index b03bafa..56f85c3 100644 --- a/src/geosearch_dk/settingsdialog.py +++ b/src/geosearch_dk/settingsdialog.py @@ -21,12 +21,21 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4 import uic -#from ui_settings import Ui_Dialog FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui_settings.ui')) +MUNCODE_REGEX = '[0-9,]*' + + class SettingsDialog (QDialog, FORM_CLASS): def __init__(self): QDialog.__init__(self) self.setupUi(self) + + regex = QRegExp('', Qt.CaseInsensitive) + self.muncodeValidator = QRegExpValidator(MUNCODE_REGEX) + self.kommunekoderLineEdit.setValidator( + self.muncodeValidator, + self.kommunekoderLineEdit + ) diff --git a/src/geosearch_dk/ui_settings.ui b/src/geosearch_dk/ui_settings.ui index faf8ff7..6998df4 100644 --- a/src/geosearch_dk/ui_settings.ui +++ b/src/geosearch_dk/ui_settings.ui @@ -26,7 +26,7 @@ - 0 + 1 From 7755cd3974b9c03900e15684587228a7e183f5ec Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Wed, 13 May 2015 15:27:51 +0200 Subject: [PATCH 10/10] We can now filter by kommunekode, removed deprecated python2 methods --- src/geosearch_dk/searchbox.py | 127 +++++++++++++++-------------- src/geosearch_dk/settingsdialog.py | 7 +- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index d5acd6f..bfc9c1a 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -114,64 +114,70 @@ def parseresponse(self, response): 'Invalid JSON response from server: ' + result, __package__ ) # Check if we have an auth error - if 'User not found' in response or 'User not authenticated' in response: + if 'User not found' in response or \ + 'User not authenticated' in response: QMessageBox.warning( None, 'Bruger afvist af Kortforsyningen', - 'Manglende eller ukorrekt brugernavn og password til Kortforsyningen.\n\n' + 'Manglende eller ukorrekt brugernavn og password \ + til Kortforsyningen.\n\n' + 'Kortforsyningen svarede:\n' + str(response) ) self.show_settings_dialog() return None - if not obj.has_key('status'): - QgsMessageLog.logMessage('Unexpected result from server: ' + result, __package__) + if 'status' not in obj: + QgsMessageLog.logMessage( + 'Unexpected result from server: ' + result, __package__ + ) return None if not obj['status'] == 'OK': - QgsMessageLog.logMessage('Server reported an error: ' + obj['message'], __package__) + QgsMessageLog.logMessage( + 'Server reported an error: ' + obj['message'], __package__ + ) return None data = obj['data'] # Make tuple with ("text", object) for each result - return [(e['presentationString'], e) for e in data ] + return [(e['presentationString'], e) for e in data] def setupCrsTransform(self): - if not QgsCoordinateReferenceSystem is None: - srcCrs = QgsCoordinateReferenceSystem( 25832, QgsCoordinateReferenceSystem.EpsgCrsId ) - dstCrs = qgisutils.getCurrentCrs( self.qgisIface ) - #print "CRS: ", dstCrs.toWkt() - self.crsTransform = QgsCoordinateTransform( srcCrs, dstCrs ) + if QgsCoordinateReferenceSystem is not None: + srcCrs = QgsCoordinateReferenceSystem( + 25832, QgsCoordinateReferenceSystem.EpsgCrsId + ) + dstCrs = qgisutils.getCurrentCrs(self.qgisIface) + self.crsTransform = QgsCoordinateTransform(srcCrs, dstCrs) - def setMarkerGeom( self, geom ): + def setMarkerGeom(self, geom): # Show geometry self.clearMarkerGeom() if geom.wkbType() == QGis.WKBPoint: - m = QgsVertexMarker( self.qgisIface.mapCanvas() ) - m.setCenter( geom.asPoint() ) -## else: -## m = QgsRubberBand(self.qgisIface.mapCanvas(), QGis.Line) -## m.setToGeometry( geom , None) -## m.setColor(QColor(255,0,0)) + m = QgsVertexMarker(self.qgisIface.mapCanvas()) + m.setCenter(geom.asPoint()) elif geom.wkbType() == QGis.WKBLineString: - m = QgsRubberBand(self.qgisIface.mapCanvas(), False) # False = not a polygon - m.setToGeometry( geom , None) + m = QgsRubberBand(self.qgisIface.mapCanvas(), False) # not polygon + m.setToGeometry(geom, None) elif geom.wkbType() == QGis.WKBPolygon: m = QgsRubberBand(self.qgisIface.mapCanvas(), False) - m.setToGeometry( QgsGeometry.fromPolyline(geom.asPolygon()[0] ) , None) + m.setToGeometry( + QgsGeometry.fromPolyline(geom.asPolygon()[0]), + None + ) - m.setColor(QColor(255,0,0)) + m.setColor(QColor(255, 0, 0)) self.marker = m - def clearMarkerGeom( self ): - if not self.marker is None: - self.qgisIface.mapCanvas().scene().removeItem( self.marker ) + def clearMarkerGeom(self): + if self.marker is not None: + self.qgisIface.mapCanvas().scene().removeItem(self.marker) self.marker = None - def clear( self ): + def clear(self): self.clearMarkerGeom() self.ui.searchEdit.clear() @@ -179,40 +185,39 @@ def doSearch(self): self.completion.preventSuggest() o = self.completion.selectedObject - #print o + # print o if not o: return # Create a QGIS geom to represent object geom = None - if o.has_key('geometryWkt'): + if 'geometryWkt' in o: wkt = o['geometryWkt'] # Fix invalid wkt if wkt.startswith('BOX'): wkt = 'LINESTRING' + wkt[3:] - geom = QgsGeometry.fromRect( QgsGeometry.fromWkt( wkt ).boundingBox() ) + geom = QgsGeometry.fromRect( + QgsGeometry.fromWkt(wkt).boundingBox() + ) else: - geom = QgsGeometry.fromWkt( wkt ) - elif o.has_key('xMin'): - geom = QgsGeometry.fromRect( QgsRectangle( o['xMin'], o['yMin'], o['xMax'], o['yMax']) ) + geom = QgsGeometry.fromWkt(wkt) + elif 'xMin' in o: + geom = QgsGeometry.fromRect( + QgsRectangle(o['xMin'], o['yMin'], o['xMax'], o['yMax']) + ) else: - geom = QgsGeometry.fromPoint(QgsPoint(o['x'] , o['y'])) + geom = QgsGeometry.fromPoint(QgsPoint(o['x'], o['y'])) # Zoom to feature bufgeom = geom.buffer(200.0, 2) - #if self.qgisIface.mapCanvas().mapRenderer().hasCrsTransformEnabled(): bufgeom.transform(self.crsTransform) - rect= bufgeom.boundingBox() - #print "BBOX: ", rect.toString() - mc=self.qgisIface.mapCanvas() - mc.setExtent( rect ) + rect = bufgeom.boundingBox() + mc = self.qgisIface.mapCanvas() + mc.setExtent(rect) # Mark the spot - #print "Geom: ", geom.exportToWkt() - #if self.qgisIface.mapCanvas().mapRenderer().hasCrsTransformEnabled(): - geom.transform( self.crsTransform ) - #print"Transformed geom: ", geom.exportToWkt() - self.setMarkerGeom( geom ) + geom.transform(self.crsTransform) + self.setMarkerGeom(geom) mc.refresh() @@ -221,7 +226,9 @@ def show_settings_dialog(self): dlg = settingsdialog.SettingsDialog() dlg.loginLineEdit.setText(self.config['username']) dlg.passwordLineEdit.setText(self.config['password']) - dlg.kommunekoderLineEdit.setText(','.join(map(str, self.config['muncodes']))) + dlg.kommunekoderLineEdit.setText( + ','.join(map(str, self.config['muncodes'])) + ) # show the dialog dlg.show() result = dlg.exec_() @@ -231,21 +238,25 @@ def show_settings_dialog(self): # save settings self.config['username'] = str(dlg.loginLineEdit.text()) self.config['password'] = str(dlg.passwordLineEdit.text()) - self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',') if not k.strip() == '' ] + self.config['muncodes'] = [int(k) for k in dlg.kommunekoderLineEdit.text().split(',') if not k.strip() == ''] self.updateconfig() def show_about_dialog(self): - infoString = QCoreApplication.translate('Geosearch DK', - u"Geosearch DK lader brugeren zoome til navngivne steder i Danmark.
" - u"Pluginet benytter tjenesten 'geosearch' fra kortforsyningen.dk" - u" og kræver derfor et gyldigt login til denne tjeneste.
" - u"Pluginets webside: github.com/Septima/qgis-geosearch
" - u"Udviklet af: Septima
" - u"Mail: kontakt@septima.dk
" - u"Web: www.septima.dk\n") - QMessageBox.information(self.qgisIface.mainWindow(), "Om Geosearch DK",infoString) - - def unload( self ): + infoString = QCoreApplication.translate( + 'Geosearch DK', + u"Geosearch DK lader brugeren zoome til navngivne steder i Danmark.
" + u"Pluginet benytter tjenesten 'geosearch' fra kortforsyningen.dk" + u" og kræver derfor et gyldigt login til denne tjeneste.
" + u"Pluginets webside: github.com/Septima/qgis-geosearch
" + u"Udviklet af: Septima
" + u"Mail: kontakt@septima.dk
" + u"Web: www.septima.dk\n" + ) + QMessageBox.information( + self.qgisIface.mainWindow(), "Om Geosearch DK", infoString + ) + + def unload(self): self.completion.unload() self.clearMarkerGeom() @@ -254,10 +265,6 @@ def unload( self ): app = QApplication(sys.argv) suggest = SearchBox() - #suggest.setWindowFlags(Qt.FramelessWindowHint) suggest.show() - #charm = DragMoveCharm() - #charm.activateOn(suggest) - sys.exit(app.exec_()) diff --git a/src/geosearch_dk/settingsdialog.py b/src/geosearch_dk/settingsdialog.py index 56f85c3..b94c903 100644 --- a/src/geosearch_dk/settingsdialog.py +++ b/src/geosearch_dk/settingsdialog.py @@ -33,9 +33,8 @@ def __init__(self): QDialog.__init__(self) self.setupUi(self) - regex = QRegExp('', Qt.CaseInsensitive) - self.muncodeValidator = QRegExpValidator(MUNCODE_REGEX) + regex = QRegExp(MUNCODE_REGEX, Qt.CaseInsensitive) + self.muncodeValidator = QRegExpValidator(regex) self.kommunekoderLineEdit.setValidator( - self.muncodeValidator, - self.kommunekoderLineEdit + self.muncodeValidator )