From 155a19a1a2105626d53b471803d6581f9ba7df30 Mon Sep 17 00:00:00 2001 From: chris2oph Date: Wed, 19 Dec 2018 14:16:20 +0000 Subject: [PATCH] Improve checks for dates range in wxQt wxCalendarCtrl Account for the minimum and maximum dates supported by QDatePicker, both in the code and in the test suite, which shouldn't rely on not having any range restrictions in wxQt. Closes https://github.com/wxWidgets/wxWidgets/pull/1088 --- src/qt/calctrl.cpp | 23 ++++++++++++++++++----- tests/controls/datepickerctrltest.cpp | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/qt/calctrl.cpp b/src/qt/calctrl.cpp index cc051c09dc..b79fc84745 100644 --- a/src/qt/calctrl.cpp +++ b/src/qt/calctrl.cpp @@ -136,6 +136,10 @@ bool wxCalendarCtrl::SetDate(const wxDateTime& date) if ( !m_qtCalendar ) return false; + if ( wxQtConvertDate( date ) > m_qtCalendar->maximumDate() || + wxQtConvertDate( date ) < m_qtCalendar->minimumDate() ) + return false; + m_qtCalendar->blockSignals(true); m_qtCalendar->setSelectedDate(wxQtConvertDate(date)); m_qtCalendar->blockSignals(false); @@ -171,12 +175,21 @@ bool wxCalendarCtrl::GetDateRange(wxDateTime *lowerdate, if ( !m_qtCalendar ) return false; - if (lowerdate) - *lowerdate = wxQtConvertDate(m_qtCalendar->minimumDate()); - if (upperdate) - *upperdate = wxQtConvertDate(m_qtCalendar->maximumDate()); + bool status = false; - return true; + if ( lowerdate ) + { + *lowerdate = wxQtConvertDate(m_qtCalendar->minimumDate()); + status = true; + } + + if ( upperdate ) + { + *upperdate = wxQtConvertDate(m_qtCalendar->maximumDate()); + status = true; + } + + return status; } // Copied from wxMSW diff --git a/tests/controls/datepickerctrltest.cpp b/tests/controls/datepickerctrltest.cpp index 403e18ac01..2c1bc0a760 100644 --- a/tests/controls/datepickerctrltest.cpp +++ b/tests/controls/datepickerctrltest.cpp @@ -85,8 +85,13 @@ void DatePickerCtrlTestCase::Range() // minimum as it doesn't support dates before 1601-01-01, hence don't rely // on GetRange() returning false. wxDateTime dtRangeStart, dtRangeEnd; + + // Default end date for QT is 31/12/7999 which is considered valid, + // therefore we should omit this assertion for QT +#ifndef __WXQT__ m_datepicker->GetRange(&dtRangeStart, &dtRangeEnd); CPPUNIT_ASSERT( !dtRangeEnd.IsValid() ); +#endif // After we set it we should be able to get it back. const wxDateTime