-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrolling_datetime_edit.py
32 lines (29 loc) · 1.33 KB
/
rolling_datetime_edit.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
from qgis.PyQt.QtWidgets import QDateTimeEdit
from qgis.core import Qgis as QGis
class rolling_datetime_edit(QDateTimeEdit):
def __init__(self, parent):
super(rolling_datetime_edit, self).__init__(parent)
self.syncDateTime = None
def setSyncDateTime(self, syncDateTime):
self.syncDateTime = syncDateTime
def stepBy(self, steps):
section = self.currentSection()
if self.syncDateTime is not None:
diff = self.dateTime().msecsTo(self.syncDateTime.dateTime())
if section == QDateTimeEdit.SecondSection:
nextDate = self.dateTime().addSecs(steps)
elif section == QDateTimeEdit.MinuteSection:
nextDate = self.dateTime().addSecs(steps * 60)
elif section == QDateTimeEdit.HourSection:
nextDate = self.dateTime().addSecs(steps * 60 * 60)
elif section == QDateTimeEdit.DaySection:
nextDate = self.dateTime().addDays(steps)
elif section == QDateTimeEdit.MonthSection:
nextDate = self.dateTime().addMonths(steps)
elif section == QDateTimeEdit.YearSection:
nextDate = self.dateTime().addYears(steps)
else:
return
self.setDateTime(nextDate)
if self.syncDateTime is not None:
self.syncDateTime.setDateTime(self.dateTime().addMSecs(diff))