forked from sourcepole/pgversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ui_diff.py
130 lines (96 loc) · 4.77 KB
/
Ui_diff.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
# -*- coding: utf-8 -*-
"""
Module implementing DiffDlg.
"""
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.gui import *
from ..dbtools.dbTools import *
from ..pgVersionTools import PgVersionTools
from Ui_Ui_diff import Ui_DiffDlg
class DiffDlg(QDialog, Ui_DiffDlg):
"""
Class documentation goes here.
"""
def __init__(self, iface, parent = None):
"""
Constructor
"""
QDialog.__init__(self, parent)
self.setupUi(self)
self.iface = iface
self.tools = PgVersionTools(parent)
self.dateEditRev1.setDate(QDate.currentDate())
self.dateEditRev2.setDate(QDate.currentDate())
canvas = self.iface.mapCanvas()
theLayer = self.iface.activeLayer()
provider = theLayer.dataProvider()
uri = provider.dataSourceUri()
myDb = self.tools.layerDB('logview', theLayer)
mySchema = QgsDataSourceURI(uri).schema()
myTable = QgsDataSourceURI(uri).table()
if len(mySchema) == 0:
mySchema = 'public'
sql = "select revision from versions.pgvslogview('"+mySchema+"."+myTable.replace('_version', '')+"') order by revision desc"
result = myDb.read(sql)
for i in range(len(result['REVISION'])):
self.cmbRevision1.addItem(result['REVISION'][i])
self.cmbRevision2.addItem(result['REVISION'][i])
def setDb(self, theLayer):
provider = theLayer.dataProvider()
uri = provider.dataSourceUri()
self.myDb = self.tools.layerDB('diffDlg', theLayer)
self.mySchema = QgsDataSourceURI(uri).schema()
self.myTable = QgsDataSourceURI(uri).table()
self.myKeyColumn = QgsDataSourceURI(uri).keyColumn()
if len(self.mySchema) == 0:
self.mySchema = 'public'
return
@pyqtSignature("")
def on_buttonBox_accepted(self):
if self.radioRevisionRev1.isChecked():
if self.cmbRevisionRev1.currentText() != '-----':
myRevision1 = self.cmbRevisionRev1.currentText()
if self.radioRevisionRev2.isChecked():
if self.cmbRevisionRev2.currentText() != '-----':
myRevision2 = self.cmbRevisionRev2.currentText()
if self.radioDateRev1.isChecked():
myDate = self.dateEditRev1.date().toString(Qt.ISODate)
sql = 'select revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
sql += 'where systime <= (date_part(\'epoch\'::text, \''+myDate+'\'::timestamp without time zone) * (1000)::double precision)::bigint '
sql += 'order by systime desc limit 1 '
result = self.myDb.read(sql)
myRevision1 = str(result['REVISION'][0])
if self.radioDateRev2.isChecked():
myDate = self.dateEditRev2.date().toString(Qt.ISODate)
sql = 'select revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
sql += 'where systime <= (date_part(\'epoch\'::text, \''+myDate+'\'::timestamp without time zone) * (1000)::double precision)::bigint '
sql += 'order by systime desc limit 1 '
result = self.myDb.read(sql)
myRevision2 = str(result['REVISION'][0])
pass
if self.radioHeadRev1.isChecked():
sql = 'select max(revision) as revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
result = self.myDb.read(sql)
myRevision1 = str(result['REVISION'][0])
if self.radioHeadRev2.isChecked():
sql = 'select max(revision) as revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
result = self.myDb.read(sql)
myRevision2 = str(result['REVISION'][0])
if self.radioBaseRev1.isChecked():
sql = 'select min(revision) as revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
result = self.myDb.read(sql)
myRevision1 = str(result['REVISION'][0])
if self.radioBaseRev2.isChecked():
sql = 'select min(revision) as revision from versions."'+self.mySchema+'_'+self.myTable+'_log" '
result = self.myDb.read(sql)
myRevision2 = str(result['REVISION'][0])
try:
self.emit(SIGNAL("diffExecute(QString, QString)"), myRevision1, myRevision2)
self.close()
except:
QMessageBox.information(None, 'Message', 'This combination is not implemented yet')
@pyqtSignature("")
def on_buttonBox_rejected(self):
self.close()