mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Fixes to work around Qt strangeness with date editing
This commit is contained in:
parent
c1971b552a
commit
62a5b4d459
@ -132,9 +132,11 @@ class DateEdit(QDateEdit):
|
||||
|
||||
def focusInEvent(self, x):
|
||||
self.setSpecialValueText('')
|
||||
QDateEdit.focusInEvent(self, x)
|
||||
|
||||
def focusOutEvent(self, x):
|
||||
self.setSpecialValueText(_('Undefined'))
|
||||
QDateEdit.focusOutEvent(self, x)
|
||||
|
||||
class DateTime(Base):
|
||||
|
||||
@ -142,7 +144,10 @@ class DateTime(Base):
|
||||
self.widgets = [QLabel('&'+self.col_metadata['name']+':', parent),
|
||||
DateEdit(parent)]
|
||||
w = self.widgets[1]
|
||||
w.setDisplayFormat('dd MMM yyyy')
|
||||
format = self.col_metadata['display'].get('date_format','')
|
||||
if not format:
|
||||
format = 'dd MMM yyyy'
|
||||
w.setDisplayFormat(format)
|
||||
w.setCalendarPopup(True)
|
||||
w.setMinimumDate(UNDEFINED_QDATE)
|
||||
w.setSpecialValueText(_('Undefined'))
|
||||
@ -156,7 +161,7 @@ class DateTime(Base):
|
||||
|
||||
def getter(self):
|
||||
val = self.widgets[1].date()
|
||||
if val == UNDEFINED_QDATE:
|
||||
if val <= UNDEFINED_QDATE:
|
||||
val = None
|
||||
else:
|
||||
val = qt_to_dt(val)
|
||||
|
@ -96,7 +96,7 @@ class DateDelegate(QStyledItemDelegate): # {{{
|
||||
|
||||
def displayText(self, val, locale):
|
||||
d = val.toDate()
|
||||
if d == UNDEFINED_QDATE:
|
||||
if d <= UNDEFINED_QDATE:
|
||||
return ''
|
||||
return format_date(d.toPyDate(), 'dd MMM yyyy')
|
||||
|
||||
@ -116,7 +116,7 @@ class PubDateDelegate(QStyledItemDelegate): # {{{
|
||||
|
||||
def displayText(self, val, locale):
|
||||
d = val.toDate()
|
||||
if d == UNDEFINED_QDATE:
|
||||
if d <= UNDEFINED_QDATE:
|
||||
return ''
|
||||
format = tweaks['gui_pubdate_display_format']
|
||||
if format is None:
|
||||
@ -194,7 +194,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
||||
|
||||
def displayText(self, val, locale):
|
||||
d = val.toDate()
|
||||
if d == UNDEFINED_QDATE:
|
||||
if d <= UNDEFINED_QDATE:
|
||||
return ''
|
||||
return format_date(d.toPyDate(), self.format)
|
||||
|
||||
@ -217,7 +217,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
val = editor.date()
|
||||
if val == UNDEFINED_QDATE:
|
||||
if val <= UNDEFINED_QDATE:
|
||||
val = None
|
||||
model.setData(index, QVariant(val), Qt.EditRole)
|
||||
|
||||
|
@ -209,13 +209,13 @@ class ResultCache(SearchQueryParser):
|
||||
if query == 'false':
|
||||
for item in self._data:
|
||||
if item is None: continue
|
||||
if item[loc] is None or item[loc] == UNDEFINED_DATE:
|
||||
if item[loc] is None or item[loc] <= UNDEFINED_DATE:
|
||||
matches.add(item[0])
|
||||
return matches
|
||||
if query == 'true':
|
||||
for item in self._data:
|
||||
if item is None: continue
|
||||
if item[loc] is not None and item[loc] != UNDEFINED_DATE:
|
||||
if item[loc] is not None and item[loc] > UNDEFINED_DATE:
|
||||
matches.add(item[0])
|
||||
return matches
|
||||
|
||||
|
@ -44,7 +44,7 @@ parse_date_day_first = compute_locale_info_for_parse_date()
|
||||
utc_tz = _utc_tz = tzutc()
|
||||
local_tz = _local_tz = SafeLocalTimeZone()
|
||||
|
||||
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)
|
||||
UNDEFINED_DATE = datetime(1000,1,1, tzinfo=utc_tz)
|
||||
|
||||
def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user