-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimportUpdateDialog.py
102 lines (89 loc) · 3.77 KB
/
importUpdateDialog.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
"""
/***************************************************************************
QGIS Historize Plugin
-------------------------------------------------------------------
Date : 09 Mai 2017
Copyright : (C) 2017 by William Habelt
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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import *
from qgis.core import *
from qgis.gui import *
from ui_importUpdate import Ui_ImportUpdate
from sqlexecute import SQLExecute
from dbconn import DBConn
class ImportUpdateDialog(QDialog, Ui_ImportUpdate):
"""
Class responsible for handling the update() function.
"""
def __init__(self, iface, parent=None):
QDialog.__init__(self, parent)
self.setupUi(self)
self.iface = iface
self.dbconn = DBConn(iface)
self.getAttributes()
self.setImportableTables()
def getAttributes(self):
"""Place excludable attributes in model list"""
# Model Structure used from Tutorial at
# http://pythoncentral.io/pyside-pyqt-tutorial-qlistview-and-qstandarditemmodel/
self.model = QStandardItemModel(self.listTblAttrib)
self.hasGeometry = self.iface.activeLayer().hasGeometryType()
self.provider = self.iface.activeLayer().dataProvider()
fields = self.iface.activeLayer().pendingFields()
for field in fields:
item = QStandardItem(field.name())
item.setCheckable(True)
self.model.appendRow(item)
self.listTblAttrib.setModel(self.model)
def getCheckedAttributes(self):
"""Creates a list of checked elements to be excluded"""
i = 0
exclList = list()
while self.model.item(i):
if self.model.item(i).checkState():
exclList.append(self.model.item(i).text())
i += 1
return exclList
def setImportableTables(self):
"""Populates combobox with importable tables
Name Structure <schema.tablename>"""
self.uri = QgsDataSourceURI(self.provider.dataSourceUri())
conn = self.dbconn.connectToDb(self.uri)
self.execute = SQLExecute(conn)
# Returns Result to be parsed
schemaTableList = self.execute.retrieveImportableTables()
cmbList = list()
if schemaTableList:
for entry in schemaTableList:
cmbEntry = entry[0] + '.' + entry[1]
cmbList.append(cmbEntry)
self.cmbImportTable.addItems(cmbList)
@pyqtSignature("")
def on_buttonBox_accepted(self):
"""
Run hist_tabs.update() SQL function with given parameters
"""
select = self.cmbImportTable.currentText()
exclList = self.getCheckedAttributes()
# Split the user selection for querying
splitString = select.split('.')
importSchema = splitString[0]
importTable = splitString[1]
self.execute.histTabsUpdate(importSchema, importTable, self.uri.schema(), self.iface.activeLayer().name(), self.hasGeometry, exclList)
@pyqtSignature("")
def on_buttonBox_rejected(self):
"""
Slot documentation goes here.
"""
self.close()