-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetupDialog.py
93 lines (73 loc) · 3.23 KB
/
SetupDialog.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
# -*- coding: utf-8 -*-
#
# 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.
#
# copyright : (C) 2015 by Sandro Mani / Sourcepole AG
# email : [email protected]
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from ui_SetupDialog import Ui_SetupDialog
import json
import os
class SetupDialog(QDialog, Ui_SetupDialog):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setupUi(self)
self.__setupUrlCombo(self.comboBoxRecWMS, self.toolButtonRecWMSAdd, self.toolButtonRecWMSRemove, "Rec")
self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.__restoreDefaults)
def getAllRecLayerUrls(self):
combo = self.comboBoxRecWMS
return [combo.itemText(i) for i in range(0, combo.count())]
def getRecLayerURL(self):
return self.comboBoxRecWMS.currentText()
def getRecLayerTitle(self):
return self.lineEditRecTitle.text()
def __setupUrlCombo(self, combo, addBtn, removeBtn, settingskey):
# Entries which are already present are default entries
for i in range(0, combo.count()):
combo.setItemData(i, True)
# Add user-added entries
entries = QSettings().value("FishDBPlugin/%s/Items" % settingskey)
if entries:
for entry in entries:
combo.addItem(entry, False)
# Remove button
removeBtn.setVisible(False)
combo.currentIndexChanged.connect(
lambda: removeBtn.setVisible(not combo.itemData(combo.currentIndex())))
removeBtn.clicked.connect(
lambda: combo.removeItem(combo.currentIndex()))
# Add button
addBtn.clicked.connect(lambda: self.__addUrl(combo))
# Line-edit sensitivity
combo.currentIndexChanged.connect(
lambda: combo.lineEdit().setReadOnly(combo.currentIndex() < 0 or combo.itemData(combo.currentIndex())))
combo.lineEdit().textChanged.connect(
lambda: self.__updateUrl(combo))
# Set current index
active = QSettings().value("FishDBPlugin/%s/Default" % settingskey)
combo.setCurrentIndex(-1)
if combo.count() > 0:
if active >= 0 and active < combo.count():
combo.setCurrentIndex(active)
else:
combo.setCurrentIndex(0)
# Store default
combo.currentIndexChanged.connect(
lambda: QSettings().setValue("FishDBPlugin/%s/Default" % settingskey, combo.currentIndex()))
def __addUrl(self, combo):
(url, success) = QInputDialog.getText(self, "Add URL", "URL:")
if url:
combo.addItem(url, False)
combo.setCurrentIndex(combo.count() - 1)
def __updateUrl(self, combo):
if not combo.lineEdit().isReadOnly():
combo.setItemText(combo.currentIndex(), combo.lineEdit().text())
def __restoreDefaults(self):
self.comboBoxRecWMS.setCurrentIndex(0)
self.lineEditRecTitle.setText("NIWA REC v2.0")