forked from HabeltWi/Historize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectDateDialog.py
82 lines (71 loc) · 2.83 KB
/
selectDateDialog.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
"""
/***************************************************************************
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 pyqtSignature
from PyQt4.QtGui import QDialog, QMessageBox
from qgis.core import QgsDataSourceURI
from sqlexecute import SQLExecute
from ui_selectDate import Ui_SelectDate
from dbconn import DBConn
class SelectDateDialog(QDialog, Ui_SelectDate):
"""
Class responsible for handling the date selection.
"""
def __init__(self, iface):
QDialog.__init__(self)
self.setupUi(self)
self.iface = iface
self.dbconn = DBConn(iface)
self.cmbDate.clear()
self.get_dates()
def get_dates(self):
"""Get all historized dates from layer"""
provider = self.iface.activeLayer().dataProvider()
self.uri = QgsDataSourceURI(provider.dataSourceUri())
self.conn = self.dbconn.connect_to_DB(self.uri)
# self.schema = self.uri.schema()
self.execute = SQLExecute(
self.iface, self.iface.mainWindow(), self.uri)
dateList = self.execute.retrieve_all_table_versions(
self.iface.activeLayer().name(), self.uri.schema())
if not dateList:
self.records = False
QMessageBox.warning(
self.iface.mainWindow(),
self.tr(u"Error"),
self.tr(u"No historized versions found!"))
else:
for date in dateList:
self.cmbDate.addItem(str(date[0]))
self.records = True
@pyqtSignature("")
def on_buttonBox_accepted(self):
"""
Run hist_tabs.version() SQL-function
"""
if self.records:
self.execute.get_older_table_version(
self.uri.schema(),
self.iface.activeLayer().name(),
self.cmbDate.currentText(),
self.uri)
@pyqtSignature("")
def on_buttonBox_rejected(self):
"""
Close Window and DB-Connection
"""
self.conn.close()
self.close()