Skip to content
Snippets Groups Projects
Commit e7c9e26a authored by Kien Le's avatar Kien Le
Browse files

Merge branch 'bug-#212-date_selector_format_not_changing_from_doy' into 'master'

Fix the date format not being changed from DOY

Closes #212

See merge request !241
parents 2144ed06 c0e4e97e
Loading
Pipeline #3526 passed with stage
in 10 minutes and 27 seconds
from PySide6.QtCore import Qt, QDate
from PySide6.QtCore import Qt
from PySide6.QtGui import (
QKeyEvent, QWheelEvent, QContextMenuEvent, QAction,
)
......@@ -19,7 +19,7 @@ class DayOfYearSupportedDateTextBox(QDateEdit):
super().__init__(date, parent, *args, **kwargs)
self.dateChanged.connect(self.on_date_changed)
# Store the current display format so that we know if 'DOY' is in it.
self._display_format = ''
self._raw_display_format = ''
def keyPressEvent(self, event: QKeyEvent):
"""
......@@ -38,19 +38,12 @@ class DayOfYearSupportedDateTextBox(QDateEdit):
return
super().keyPressEvent(event)
def on_date_changed(self, date: QDate):
def on_date_changed(self):
"""
On the stored date being changed, reformat and reset the date format if
the stored format contains 'DOY'.
:param date: the new data
On the stored date being changed, reset the date format so that the
displayed date can be formatted correctly.
"""
if 'DOY' in self._display_format:
format = self._display_format.replace(
'DOY',
f"'{str(date.dayOfYear())}'"
)
self.setDisplayFormat(format)
self.setDisplayFormat(self._raw_display_format)
def wheelEvent(self, event: QWheelEvent):
"""
......@@ -88,6 +81,9 @@ class DayOfYearSupportedDateTextBox(QDateEdit):
menu.addAction(select_all_action)
menu.exec(event.globalPos())
def displayFormat(self) -> str:
return self._raw_display_format
def setDisplayFormat(self, format):
"""
If 'DOY' is in format, replace it with the day of year of the date
......@@ -97,7 +93,7 @@ class DayOfYearSupportedDateTextBox(QDateEdit):
:param format: the date format being set.
"""
self._raw_display_format = format
if 'DOY' in format:
self._display_format = format
format = format.replace('DOY', f"{str(self.date().dayOfYear())}")
super().setDisplayFormat(format)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment